﻿/* 
 * This file is part of marvellous-components project.
 * 
 * The marvellous-components is free software: you can redistribute it 
 * and/or modify it under the terms of the GNU General Public License 
 * version 3 as published by the Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
using System;
using System.Collections.Generic;
using System.Text;

namespace marvellous_components.MagnificentTimeReportDataGridView
{
    /// <summary>
    /// Class represents work time. All methods except "addToCurrent" are immutable.
    /// </summary>
    public class WorkTime
    {
        int hours;
        int minutes;

        public WorkTime(int h, int m)
        {
            this.hours = h;
            if ((m < 0) || (m > 59))
            {
                throw new InvalidOperationException("WorkTime: invalid minutes.");
            }
            this.minutes = m;
        }

        public int Hours
        {
            get { return hours; }
        }
        
        public int Minutes
        {
            get { return minutes; }
        }

        public WorkTime setHour(int hour)
        {
            return new WorkTime(hour, this.minutes);
        }

        public WorkTime setMinute(int min)
        {
            return new WorkTime(this.hours, min);
        }

        public override string ToString()
        {
            string delim;
            if (minutes < 10)
            {
                delim = ":0";
            }
            else
            {
                delim = ":";
            }
            return hours + delim + minutes;
        }

        public WorkTime Add(WorkTime wt)
        {
            int h = hours + wt.Hours;
            int m = minutes + wt.Minutes;
            if (m >= 60)
            {
                h += m / 60;
                m = m % 60;
            }
            return new WorkTime(h, m);
        }

    }
}
